package com.example.zlpermissionservice.controller.inner;

import com.example.zlpermissionservice.api.UserRoleApi;
import com.example.zlpermissionservice.entity.UserRole;
import com.example.zlpermissionservice.service.IUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author zhenliu（孙凌岳）
 * @Description 内部接口 - 用户角色控制器
 * @Date 2025/6/17 16:22
 * @Version 1.0
 */
@RestController
@RequestMapping("/permission/inner/user-role")
@Api(tags = "内部接口 - 用户角色控制器", hidden = true)
public class InnerUserRoleController implements UserRoleApi {
    @Resource
    private IUserRoleService userRoleService;

    /**
     * 批量保存 用户角色关联信息
     * @param userRoleList
     * @return
     */
    @PostMapping("/batch-save")
    @ApiOperation(value = "批量保存用户角色关联", notes = "批量保存用户角色关联信息（内部RPC）")
    public Integer saveUserRoles(@RequestBody List<UserRole> userRoleList) {
        return userRoleService.batchInsert(userRoleList);
    }


    /**
     * 根据用户ID删除用户角色关联
     * @param userId
     * @return
     */
    @DeleteMapping("/{userId}")
    @ApiOperation(value = "根据用户ID删除角色关联", notes = "根据用户ID删除其角色关联信息（内部RPC）")
    public Boolean deleteUserRoleByUserId(@PathVariable Long userId) {
        return userRoleService.deleteUserRoleByUserId(userId);
    }

    /**
     * 批量删除用户角色信息
     * @param userIds
     * @return
     */
    @PostMapping("/batch-delete")
    @ApiOperation(value = "批量删除用户角色关联", notes = "根据用户ID集合批量删除角色关联信息（内部RPC）")
    public Boolean deleteByUserIds(@RequestBody List<Long> userIds) {
        return userRoleService.deleteByUserIds(userIds);
    }

}
